package com.wangyg.breadstore.configuration;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created by wangyg6 on 2019/5/16.
 */
public class ApplicationContextHolder implements ApplicationContextAware {
	private static ApplicationContext context = null;

	public static ApplicationContext getApplicationContext() {
		return context;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.context = applicationContext;
	}

	public static <T> T getBean(String name) {
		return (T) context.getBean(name);
	}
}
